package com.datastructure.test.issearchbinarytree;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class IsSearchBinaryTree {

    public boolean isValidBST (TreeNode root) {
        // write code here
        if (root==null){
            return true;
        }
        ArrayList<Integer>a=new ArrayList<>();
        inOrder(a,root);
        for (int i=0;i<a.size()-1;i++){
            if (a.get(i)>a.get(i+1)){
                return false;
            }
        }
        return true;
    }
    private static void inOrder(List<Integer> list, TreeNode root) {
        if (root==null){
            return;
        }
        inOrder(list,root.left);
        list.add(root.val);
        inOrder(list,root.right);
    }

}

class TreeNode {
    int val = 0;
    TreeNode left;
    TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }
}
